<?php
// +----------------------------------------------------------------------
// | AssetController.php 附近上传
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2018  http://www.zzuyxg.top All rights reserved.
// +----------------------------------------------------------------------
// | Author: Eric <ieyangxiaoguo@126.com>
// +----------------------------------------------------------------------
// | Date:2018-06-03
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\common\controller\BaseController;

class AssetController extends BaseController
{
    //单文件上传
    public function imgUpload()
    {
        if ($this->request->isPost()) {
            $res['code'] = 1;
            $res['msg'] = '上传成功！';

            $file = $this->request->file('file');

            $path = $this->request->param('path/s');

            if (!$path)
                $path = date('Ymd',time());

            $info = $file->rule('uniqid')->move('../public/upload/admin/'.$path.'/');
            if ($info) {
                $res['name'] = $info->getFilename();
                $res['filepath'] = '/upload/admin/'.$path.'/'.$info->getSaveName();
            } else {
                $res['code'] = 0;
                $res['msg'] = '上传失败！'.$file->getError();
            }
            return $res;
        }
    }

    public function umeUpload()
    {
        if ($this->request->isPost()) {
            $res['state'] = 'SUCCESS';
            $res['msg'] = '上传成功！';

            $file = $this->request->file('upfile');
            $date = date('Ymd',time());
            $info = $file->rule('uniqid')->move('../public/upload/umeditor/'.$date.'/');
            if ($info) {
                $res['url'] = 'upload/umeditor/'.$date.'/'.$info->getSaveName();
            } else {
                $res['state'] = 'ERROR';
            }

            return json($res);
        }
    }
}
